package com.report.controller;

import com.report.dto.ReportByIdRequest;
import com.report.dto.ReportMergeRecordRequest;
import com.report.dto.ReportResponse;
import com.report.dto.Response;
import com.report.entity.Report;
import com.report.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 合并报表
 */
@RestController
@RequestMapping("/api/report")
public class ReportController {

    @Autowired
    private ReportService reportService;


    /**
     * 更新
     *
     * @param report
     * @return
     */
    @PostMapping("/upsert")
    public Response upsertReport(@RequestBody Report report) {
        return reportService.upsertReport(report);
    }

    /**
     * 获取报表信息
     *
     * @param request
     * @return
     */
    @PostMapping("/getReport")
    public Response getReport(@RequestBody ReportByIdRequest request) {
        return reportService.getReport(request);
    }

    /**
     * 合并报表
     *
     * @param request
     * @return
     */
    @PostMapping("/merge")
    public ReportResponse mergeReports(@RequestBody ReportByIdRequest request) {
        return reportService.merge(request);
        //return reportService.mergeReportsById(request.getSjxmbh(), request.getBsdwxydms(), request.getMergeNode(), request.getTables(), request.getAuditCompanyUscc());
    }

    /**
     * 合并记录
     *
     * @param request
     * @return
     */
    @PostMapping("/merge/record")
    public Response mergeReportRecords(@RequestBody ReportMergeRecordRequest request) {
        return reportService.mergeReportRecords(request);
    }

    /**
     * 合并记录详情
     *
     * @param request
     * @return
     */
    @PostMapping("/merge/record/{id}")
    public ReportResponse mergeReportRecordInfo(@RequestBody ReportByIdRequest request) {
        return null; //reportService.mergeReportsById(request.getSjxmbh(), request.getBsdwxydm(), request.getReporttype(), request.getMergeType());
    }

    /**
     * 只传data节点的数据
     * @param report
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody Report report) {
        return reportService.save(report);
    }

}
